package com.cq.hd.admin.controller;

import com.cq.hd.admin.annotation.RequiresPermissionsDesc;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.TbMemberCardApi;
import com.cq.hd.member.api.dto.MemberCardPageDto;
import com.cq.hd.member.api.dto.MemberCardSaveDto;
import com.cq.hd.member.api.dto.MemberCardUpdateDto;
import com.cq.hd.member.api.vo.MemberCardPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "火动次卡配置相关接口")
@Slf4j
@RestController
@RequestMapping("/memberCard")
public class TbMemberCardController extends BaseController {

    private TbMemberCardApi memberCardApi;

    @Autowired
    public void setMemberCardApi(TbMemberCardApi memberCardApi) {
        this.memberCardApi = memberCardApi;
    }

    @ApiOperation(value = "保存火动次卡配置")
    @ApiImplicitParam(name = "memberCardSaveDto", value = "保存参数", paramType = "body", dataType = "MemberCardSaveDto")
    @RequiresPermissions("business:memberCard:save")
    @RequiresPermissionsDesc(menu = {"商家管理", "火动次卡配置"}, button = "保存")
    @PostMapping("/save")
    public Result<Long> saveMemberCard(@Validated @RequestBody MemberCardSaveDto memberCardSaveDto) {
        return memberCardApi.saveMemberCard(memberCardSaveDto);
    }

    @ApiOperation(value = "更新火动次卡配置")
    @ApiImplicitParam(name = "memberCardUpdateDto", value = "更新参数", paramType = "body", dataType = "MemberCardUpdateDto")
    @RequiresPermissions("business:memberCard:update")
    @RequiresPermissionsDesc(menu = {"商家管理", "火动次卡配置"}, button = "更新")
    @PostMapping("/update")
    public Result<Boolean> updateMemberCard(@Validated @RequestBody MemberCardUpdateDto memberCardUpdateDto) {
        return memberCardApi.updateMemberCard(memberCardUpdateDto);
    }

    @ApiOperation(value = "火动次卡配置列表")
    @ApiResponse(response = MemberCardPageVo.class, code = 200, message = "接口返回对象参数")
    @RequiresPermissions("business:memberCard:list")
    @RequiresPermissionsDesc(menu = {"商家管理", "火动次卡配置"}, button = "查询")
    @GetMapping("/page")
    public Result<Page<MemberCardPageVo>> pageMemberCard(MemberCardPageDto memberCardPageDto) {
        return memberCardApi.pageMemberCard(memberCardPageDto);
    }

}
